﻿namespace WMS6.BLL
{
    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.Data.Common;
    using WMS6.Common;
    using WMS6.DataEntity;
    using WMS6.DBUtility;
    using WMS6.IDAL;
    using WMS6.QueryEntity;
    using WMS6.DALFactory;

    public class InventoryMgtBLL
    {
        private static readonly IAnalyticsReportDA analyticsReportDA = DataAccess.CreateAnalyticsReportDA();
        private static readonly ICommonMethodDA commonMethod = DataAccess.CreateCommonMethod();
        private List<string> dataBaseID;
        private static readonly IInvBackUpDA invBackUpDA = DataAccess.CreateInvBackUpDA();
        private static readonly IInventoryMgtDA InventoryMgtDA = DataAccess.CreateInventoryMgtDA();
        private static readonly IInvLotDA invLotDA = DataAccess.CreateInvLotDA();
        private static readonly IInvLotLocLpnDA invLotLocLpnDA = DataAccess.CreateInvLotLocLpnDA();
        private static readonly IInvSkuLocDA invSkuLocDA = DataAccess.CreateInvSkuLocDA();
        private static readonly IInvTransDA invTransDA = DataAccess.CreateInvTransDA();
        private static readonly ILocationDA locationDA = DataAccess.CreateLocationDA();
        private static readonly ILotAttributeDA lotAttributeDA = DataAccess.CreateLotAttributeDA();
        private static readonly ILpnDA lpnDA = DataAccess.CreateLpnDA();
        private static readonly IPackDA packDA = DataAccess.CreatePackDA();
        private static readonly IPickDetailDA pickDetailDA = DataAccess.CreatePickDetailDA();
        private PubParasInfo pubParasInfo;
        private static readonly ISkuDA skuDA = DataAccess.CreateSkuDA();
        private static readonly ISysSettingDA sysSettingDA = DataAccess.CreateSysSettingDA();
        private static readonly ITransferDA transferDA = DataAccess.CreateTransferDA();
        private static readonly ITransferDetailDA transferDetailDA = DataAccess.CreateTransferDetailDA();

        public InventoryMgtBLL()
        {
            this.pubParasInfo = null;
        }

        public InventoryMgtBLL(string currentWH)
        {
            this.pubParasInfo = null;
            if (!string.IsNullOrEmpty(currentWH))
            {
                this.dataBaseID = commonMethod.GetDataBaseID(currentWH);
                if (this.dataBaseID == null)
                {
                    PublicMethod.GetInstance().ShowAlertMessage("C001");
                }
            }
            else
            {
                PublicMethod.GetInstance().ShowAlertMessage("C002");
            }
        }

        public InventoryMgtBLL(PubParasInfo tempPubParasInfo)
        {
            this.pubParasInfo = null;
            if (!string.IsNullOrEmpty(tempPubParasInfo.CurrentWH))
            {
                this.dataBaseID = commonMethod.GetDataBaseID(tempPubParasInfo.CurrentWH);
                if (this.dataBaseID == null)
                {
                    PublicMethod.GetInstance().ShowAlertMessage("C001", this.pubParasInfo.UserLanguage);
                }
                else
                {
                    this.pubParasInfo = new PubParasInfo();
                    this.pubParasInfo = tempPubParasInfo;
                }
            }
            else
            {
                PublicMethod.GetInstance().ShowAlertMessage("C002", this.pubParasInfo.UserLanguage);
            }
        }

        public string ExecuteInvMoves(List<InvMovesInfo> invMovesInfo)
        {
            string temp = string.Empty;
            string whLoginID = this.dataBaseID[0];
            DataBase dataBase = new DataBase();
            DbConnection conn = dataBase.connection;
            conn.Open();
            DbTransaction tran = conn.BeginTransaction();
            try
            {
                if ((invMovesInfo != null) && (invMovesInfo.Count > 0))
                {
                    SysSettingInfo sysSetting = sysSettingDA.GetSysSettingByID(dataBase, tran, "LPNWhetherToallowDuplicate", whLoginID, this.pubParasInfo);
                    InboundHelper inboundHelper = new InboundHelper();
                    for (int i = 0; i < invMovesInfo.Count; i++)
                    {
                        if (((sysSetting != null) && (sysSetting.Value == "N")) && lpnDA.CheckLpnIDUnique(dataBase, tran, invMovesInfo[i].ToLpn, whLoginID))
                        {
                            throw new Exception("LPN:" + invMovesInfo[i].ToLpn + " 已经存在,请重新输入!");
                        }
                        if (!locationDA.CheckLocationIDUnique(dataBase, tran, invMovesInfo[i].ToLoc, whLoginID))
                        {
                            PublicMethod.GetInstance().ShowAlertMessage("F5050_001", this.pubParasInfo.UserLanguage);
                        }
                        if (!(string.IsNullOrEmpty(invMovesInfo[i].PackID) || string.IsNullOrEmpty(invMovesInfo[i].UomID)))
                        {
                            invMovesInfo[i].MoveQty = inboundHelper.ExchangeUom(dataBase, tran, invMovesInfo[i].PackID, invMovesInfo[i].UomID, invMovesInfo[i].MoveQty, "W", whLoginID);
                            invMovesInfo[i].FromMoveQty = inboundHelper.ExchangeUom(dataBase, tran, invMovesInfo[i].PackID, invMovesInfo[i].UomID, invMovesInfo[i].FromMoveQty, "W", whLoginID);
                        }
                        this.UpdateInvLotLocLpn4Moves(dataBase, tran, invMovesInfo[i], InvMoveType.Move, whLoginID);
                        this.UpdateInvSkuLoc4Moves(dataBase, tran, invMovesInfo[i], InvMoveType.Move, whLoginID);
                        this.UpdateLpn4Moves(dataBase, tran, invMovesInfo[i], whLoginID);
                        temp = temp + this.InsertInvMovesTrans(dataBase, tran, invMovesInfo[i], TransSourceType.ConsoleMove, whLoginID) + ",";
                    }
                }
                tran.Commit();
            }
            catch (Exception ex)
            {
                tran.Rollback();
                CommonErrorHandler.ErrorHandler(ex, LogType.Error);
            }
            finally
            {
                conn.Close();
            }
            return temp;
        }

        public DataSet GetInventoryByQueryEnetiy(InventoryQueryEntity inventoryQueryEntity)
        {
            InventoryQueryEntity inventoryQuery = inventoryQueryEntity;
            List<string> sqlWhere = new List<string>();
            if (!string.IsNullOrEmpty(inventoryQuery.OwnerID))
            {
                sqlWhere.Add(" VI.OWNER_ID " + inventoryQuery.OwnerID);
            }
            if (!string.IsNullOrEmpty(inventoryQuery.Sku))
            {
                sqlWhere.Add(" VI.SKU_ID " + inventoryQuery.Sku);
            }
            if (!string.IsNullOrEmpty(inventoryQuery.Descr))
            {
                sqlWhere.Add(" VI.DESCR " + inventoryQuery.Descr);
            }
            if (!string.IsNullOrEmpty(inventoryQuery.SkuClassID))
            {
                sqlWhere.Add(" SKU_CLASS_ID " + inventoryQuery.SkuClassID);
            }
            if (!string.IsNullOrEmpty(inventoryQuery.LotAttributeID))
            {
                sqlWhere.Add(" VI.LOT " + inventoryQuery.LotAttributeID);
            }
            if (!string.IsNullOrEmpty(inventoryQuery.Location))
            {
                sqlWhere.Add(" VI.LOC " + inventoryQuery.Location);
            }
            if (!string.IsNullOrEmpty(inventoryQuery.LPN))
            {
                sqlWhere.Add(" VI.LPN_ID " + inventoryQuery.LPN);
            }
            if (!string.IsNullOrEmpty(inventoryQuery.QTY))
            {
                sqlWhere.Add(" QTY " + inventoryQuery.QTY);
            }
            if (!string.IsNullOrEmpty(inventoryQuery.LotAttribute1))
            {
                sqlWhere.Add(" LOT_ATTR01 " + inventoryQuery.LotAttribute1);
            }
            if (!string.IsNullOrEmpty(inventoryQuery.LotAttribute2))
            {
                sqlWhere.Add(" LOT_ATTR02 " + inventoryQuery.LotAttribute2);
            }
            if (!string.IsNullOrEmpty(inventoryQuery.LotAttribute3))
            {
                sqlWhere.Add(" LOT_ATTR03 " + inventoryQuery.LotAttribute3);
            }
            if (!string.IsNullOrEmpty(inventoryQuery.LotAttribute4))
            {
                sqlWhere.Add(" LOT_ATTR04 " + inventoryQuery.LotAttribute4);
            }
            if (!string.IsNullOrEmpty(inventoryQuery.LotAttribute5))
            {
                sqlWhere.Add(" LOT_ATTR05 " + inventoryQuery.LotAttribute5);
            }
            if (!string.IsNullOrEmpty(inventoryQuery.LotAttribute6))
            {
                sqlWhere.Add(" LOT_ATTR06 " + inventoryQuery.LotAttribute6);
            }
            if (!string.IsNullOrEmpty(inventoryQuery.LotAttribute7))
            {
                sqlWhere.Add(" LOT_ATTR07 " + inventoryQuery.LotAttribute7);
            }
            if (!string.IsNullOrEmpty(inventoryQuery.LotAttribute8))
            {
                sqlWhere.Add(" LOT_ATTR08 " + inventoryQuery.LotAttribute8);
            }
            if (!string.IsNullOrEmpty(inventoryQuery.LotAttribute9))
            {
                sqlWhere.Add(" LOT_ATTR09 " + inventoryQuery.LotAttribute9);
            }
            if (!string.IsNullOrEmpty(inventoryQuery.LotAttribute10))
            {
                sqlWhere.Add(" LOT_ATTR10 " + inventoryQuery.LotAttribute10);
            }
            if (!string.IsNullOrEmpty(inventoryQuery.ProductDate))
            {
                sqlWhere.Add(inventoryQuery.ProductDate.Replace("@ProductDate@", " PRODUCE_DATE "));
            }
            if (!string.IsNullOrEmpty(inventoryQuery.ExpiryDate))
            {
                sqlWhere.Add(inventoryQuery.ExpiryDate.Replace("@ExpiryDate@", " EXPIRY_DATE "));
            }
            if (!string.IsNullOrEmpty(inventoryQuery.ReceiptDate))
            {
                sqlWhere.Add(inventoryQuery.ReceiptDate.Replace("@ReceiptDate@", " RECEIPT_DATE "));
            }
            if (!string.IsNullOrEmpty(inventoryQuery.ExternalLot))
            {
                sqlWhere.Add(" EXTERNAL_LOT " + inventoryQuery.ExternalLot);
            }
            if (!string.IsNullOrEmpty(inventoryQuery.VendorID))
            {
                sqlWhere.Add(" VENDOR_ID " + inventoryQuery.VendorID);
            }
            return InventoryMgtDA.GetInventoryByQueryEnetiy(inventoryQuery, sqlWhere, this.dataBaseID[0], this.pubParasInfo);
        }

        public InventoryInfo GetInventoryInfoByLpnID(string lpnID)
        {
            string whLoginID = this.dataBaseID[0];
            InventoryInfo inventoryInfo = InventoryMgtDA.GetInventoryInfoByLpnID(lpnID, whLoginID);
            if (inventoryInfo != null)
            {
                List<PickDetailInfo> pickDetailInfo = pickDetailDA.GetPickDetailByLpnID(lpnID, whLoginID, this.pubParasInfo);
                if ((pickDetailInfo != null) && (pickDetailInfo.Count > 0))
                {
                    inventoryInfo.IsLpnPick = "Y";
                    return inventoryInfo;
                }
                inventoryInfo.IsLpnPick = "N";
            }
            return inventoryInfo;
        }

        public string ImportTransferByDataSet(DataSet ds, string projectID, string transferID)
        {
            string result = transferID;
            if ((((string.Compare("ST", projectID, true) == 0) && (ds != null)) && (ds.Tables.Count > 0)) && (ds.Tables[0].Rows.Count > 0))
            {
                DataBase dataBase = new DataBase();
                DbConnection conn = dataBase.connection;
                conn.Open();
                DbTransaction tran = conn.BeginTransaction();
                try
                {
                    List<TransferDetailInfo> transferDetailInfos = transferDetailDA.GetTransferDetailListByID(dataBase, tran, transferID, this.dataBaseID[0]);
                    if ((transferDetailInfos != null) && (transferDetailInfos.Count > 0))
                    {
                        throw new Exception(string.Format("Error:{0}已存在明细行向.", transferID));
                    }
                    DataTable dt = ds.Tables[0];
                    List<TransferDetailInfo> transferDetailInfoList = new List<TransferDetailInfo>();
                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        string fromOwnerID = dt.Rows[i]["FROM_OWNER_ID"].ToString().Trim();
                        string fromSkuID = dt.Rows[i]["FROM_SKU_ID"].ToString().Trim();
                        string fromLoc = dt.Rows[i]["FROM_LOC"].ToString().Trim();
                        decimal fromQty = (dt.Rows[i]["FROM_QTY"].ToString().Trim() == "") ? 0M : decimal.Parse(dt.Rows[i]["FROM_QTY"].ToString().Trim());
                        string toLotAttr08 = dt.Rows[i]["TO_LOT_ATTR08"].ToString().Trim();
                        string toLoc = dt.Rows[i]["TO_LOC"].ToString().Trim();
                        LotAttributeInfo lotAttributeInfo = new LotAttributeInfo {
                            OwnerID = fromOwnerID,
                            SkuID = fromSkuID,
                            LotAttr08 = "未拆"
                        };
                        SkuInfo skuInfo = skuDA.GetSkuByID(fromOwnerID, fromSkuID, this.dataBaseID[0]);
                        PackInfo packInfo = packDA.GetPackByID(skuInfo.PackID, this.dataBaseID[0]);
                        List<InventoryInfo> inventoryInfoList = InventoryMgtDA.GetInventoryInfoByLotAttribute(dataBase, tran, lotAttributeInfo, fromLoc, "", "", this.dataBaseID[0]);
                        decimal availableQty = 0M;
                        for (int j = 0; j < inventoryInfoList.Count; j++)
                        {
                            TransferDetailInfo transferDetailInfo;
                            string lotID;
                            LotAttributeInfo lotInfo;
                            ReceiptLotInfo receiptLotInfo = new ReceiptLotInfo {
                                LotAttr01 = inventoryInfoList[j].LotAttr01,
                                LotAttr02 = inventoryInfoList[j].LotAttr02,
                                LotAttr03 = inventoryInfoList[j].LotAttr03,
                                LotAttr04 = inventoryInfoList[j].LotAttr04,
                                LotAttr05 = inventoryInfoList[j].LotAttr05,
                                LotAttr06 = inventoryInfoList[j].LotAttr06,
                                LotAttr07 = inventoryInfoList[j].LotAttr07,
                                LotAttr08 = toLotAttr08,
                                LotAttr09 = inventoryInfoList[j].LotAttr09,
                                LotAttr10 = inventoryInfoList[j].LotAttr10,
                                ProduceDate = inventoryInfoList[j].ProduceDate,
                                ExpiryDate = inventoryInfoList[j].ExpiryDate,
                                ReceiptDate = inventoryInfoList[j].ReceiptDate,
                                ExternalLot = inventoryInfoList[j].ExternalLot,
                                VendorID = inventoryInfoList[j].VendorID
                            };
                            availableQty += inventoryInfoList[j].AvailableQty;
                            if (availableQty < fromQty)
                            {
                                transferDetailInfo = new TransferDetailInfo {
                                    FromOwnerID = inventoryInfoList[j].OwnerID,
                                    FromSkuID = inventoryInfoList[j].SkuID,
                                    FromSkuDescr = inventoryInfoList[j].SkuDescr,
                                    FromLoc = inventoryInfoList[j].Loc,
                                    FromLot = inventoryInfoList[j].Lot,
                                    FromLpnID = inventoryInfoList[j].LpnID,
                                    FromQty = inventoryInfoList[j].AvailableQty,
                                    FromPackID = skuInfo.PackID,
                                    FromUomID = packInfo.PackUom1,
                                    ToOwnerID = inventoryInfoList[j].OwnerID,
                                    ToSkuID = inventoryInfoList[j].SkuID,
                                    ToSkuDescr = inventoryInfoList[j].SkuDescr,
                                    ToLoc = toLoc,
                                    ToLpnID = inventoryInfoList[j].LpnID,
                                    ToQty = inventoryInfoList[j].AvailableQty,
                                    ToPackID = skuInfo.PackID,
                                    ToUomID = packInfo.PackUom1
                                };
                                lotID = lotAttributeDA.CheckIsHasSameLot(dataBase, tran, receiptLotInfo, fromOwnerID, fromSkuID, this.dataBaseID[0]);
                                if (string.IsNullOrEmpty(lotID))
                                {
                                    lotInfo = new LotAttributeInfo {
                                        Lot = commonMethod.GenNextNumStr(dataBase, tran, "LOT_ATTRIBUTE", this.dataBaseID[0]),
                                        LotAttr01 = receiptLotInfo.LotAttr01,
                                        LotAttr02 = receiptLotInfo.LotAttr02,
                                        LotAttr03 = receiptLotInfo.LotAttr03,
                                        LotAttr04 = receiptLotInfo.LotAttr04,
                                        LotAttr05 = receiptLotInfo.LotAttr05,
                                        LotAttr06 = receiptLotInfo.LotAttr06,
                                        LotAttr07 = receiptLotInfo.LotAttr07,
                                        LotAttr08 = receiptLotInfo.LotAttr08,
                                        LotAttr09 = receiptLotInfo.LotAttr09,
                                        LotAttr10 = receiptLotInfo.LotAttr10,
                                        OwnerID = fromOwnerID,
                                        SkuID = fromSkuID,
                                        ProduceDate = receiptLotInfo.ProduceDate,
                                        ReceiptDate = receiptLotInfo.ReceiptDate,
                                        ExpiryDate = receiptLotInfo.ExpiryDate,
                                        ExternalLot = receiptLotInfo.ExternalLot,
                                        VendorID = receiptLotInfo.VendorID,
                                        CreatedBy = this.pubParasInfo.UserID,
                                        CreatedDate = DateTime.Now,
                                        UpdatedBy = this.pubParasInfo.UserID,
                                        UpdatedDate = DateTime.Now
                                    };
                                    lotAttributeDA.InsertLotAttribute(dataBase, tran, lotInfo, this.dataBaseID[0]);
                                    transferDetailInfo.ToLot = lotInfo.Lot;
                                }
                                else
                                {
                                    transferDetailInfo.ToLot = lotID;
                                }
                                transferDetailInfo.TransferDate = DateTime.Now;
                                transferDetailInfo.Status = "New";
                                transferDetailInfo.Udf1 = inventoryInfoList[j].AvailableQty.ToString();
                                transferDetailInfo.TransferLotInfo = receiptLotInfo;
                                transferDetailInfoList.Add(transferDetailInfo);
                            }
                            else
                            {
                                if (availableQty == fromQty)
                                {
                                    transferDetailInfo = new TransferDetailInfo {
                                        FromOwnerID = inventoryInfoList[j].OwnerID,
                                        FromSkuID = inventoryInfoList[j].SkuID,
                                        FromSkuDescr = inventoryInfoList[j].SkuDescr,
                                        FromLoc = inventoryInfoList[j].Loc,
                                        FromLot = inventoryInfoList[j].Lot,
                                        FromLpnID = inventoryInfoList[j].LpnID,
                                        FromQty = inventoryInfoList[j].AvailableQty,
                                        FromPackID = skuInfo.PackID,
                                        FromUomID = packInfo.PackUom1,
                                        ToOwnerID = inventoryInfoList[j].OwnerID,
                                        ToSkuID = inventoryInfoList[j].SkuID,
                                        ToSkuDescr = inventoryInfoList[j].SkuDescr,
                                        ToLoc = toLoc,
                                        ToLpnID = inventoryInfoList[j].LpnID,
                                        ToQty = inventoryInfoList[j].AvailableQty,
                                        ToPackID = skuInfo.PackID,
                                        ToUomID = packInfo.PackUom1
                                    };
                                    lotID = lotAttributeDA.CheckIsHasSameLot(dataBase, tran, receiptLotInfo, fromOwnerID, fromSkuID, this.dataBaseID[0]);
                                    if (string.IsNullOrEmpty(lotID))
                                    {
                                        lotInfo = new LotAttributeInfo {
                                            Lot = commonMethod.GenNextNumStr(dataBase, tran, "LOT_ATTRIBUTE", this.dataBaseID[0]),
                                            LotAttr01 = receiptLotInfo.LotAttr01,
                                            LotAttr02 = receiptLotInfo.LotAttr02,
                                            LotAttr03 = receiptLotInfo.LotAttr03,
                                            LotAttr04 = receiptLotInfo.LotAttr04,
                                            LotAttr05 = receiptLotInfo.LotAttr05,
                                            LotAttr06 = receiptLotInfo.LotAttr06,
                                            LotAttr07 = receiptLotInfo.LotAttr07,
                                            LotAttr08 = receiptLotInfo.LotAttr08,
                                            LotAttr09 = receiptLotInfo.LotAttr09,
                                            LotAttr10 = receiptLotInfo.LotAttr10,
                                            OwnerID = fromOwnerID,
                                            SkuID = fromSkuID,
                                            ProduceDate = receiptLotInfo.ProduceDate,
                                            ReceiptDate = receiptLotInfo.ReceiptDate,
                                            ExpiryDate = receiptLotInfo.ExpiryDate,
                                            ExternalLot = receiptLotInfo.ExternalLot,
                                            VendorID = receiptLotInfo.VendorID,
                                            CreatedBy = this.pubParasInfo.UserID,
                                            CreatedDate = DateTime.Now,
                                            UpdatedBy = this.pubParasInfo.UserID,
                                            UpdatedDate = DateTime.Now
                                        };
                                        lotAttributeDA.InsertLotAttribute(dataBase, tran, lotInfo, this.dataBaseID[0]);
                                        transferDetailInfo.ToLot = lotInfo.Lot;
                                    }
                                    else
                                    {
                                        transferDetailInfo.ToLot = lotID;
                                    }
                                    transferDetailInfo.TransferDate = DateTime.Now;
                                    transferDetailInfo.Status = "New";
                                    transferDetailInfo.Udf1 = inventoryInfoList[j].AvailableQty.ToString();
                                    transferDetailInfo.TransferLotInfo = receiptLotInfo;
                                    transferDetailInfoList.Add(transferDetailInfo);
                                }
                                else
                                {
                                    decimal diffQty = availableQty - fromQty;
                                    transferDetailInfo = new TransferDetailInfo {
                                        FromOwnerID = inventoryInfoList[j].OwnerID,
                                        FromSkuID = inventoryInfoList[j].SkuID,
                                        FromSkuDescr = inventoryInfoList[j].SkuDescr,
                                        FromLoc = inventoryInfoList[j].Loc,
                                        FromLot = inventoryInfoList[j].Lot,
                                        FromLpnID = inventoryInfoList[j].LpnID,
                                        FromQty = inventoryInfoList[j].AvailableQty - diffQty,
                                        FromPackID = skuInfo.PackID,
                                        FromUomID = packInfo.PackUom1,
                                        ToOwnerID = inventoryInfoList[j].OwnerID,
                                        ToSkuID = inventoryInfoList[j].SkuID,
                                        ToSkuDescr = inventoryInfoList[j].SkuDescr,
                                        ToLoc = toLoc,
                                        ToLpnID = inventoryInfoList[j].LpnID,
                                        ToQty = inventoryInfoList[j].AvailableQty - diffQty,
                                        ToPackID = skuInfo.PackID,
                                        ToUomID = packInfo.PackUom1
                                    };
                                    lotID = lotAttributeDA.CheckIsHasSameLot(dataBase, tran, receiptLotInfo, fromOwnerID, fromSkuID, this.dataBaseID[0]);
                                    if (string.IsNullOrEmpty(lotID))
                                    {
                                        lotInfo = new LotAttributeInfo {
                                            Lot = commonMethod.GenNextNumStr(dataBase, tran, "LOT_ATTRIBUTE", this.dataBaseID[0]),
                                            LotAttr01 = receiptLotInfo.LotAttr01,
                                            LotAttr02 = receiptLotInfo.LotAttr02,
                                            LotAttr03 = receiptLotInfo.LotAttr03,
                                            LotAttr04 = receiptLotInfo.LotAttr04,
                                            LotAttr05 = receiptLotInfo.LotAttr05,
                                            LotAttr06 = receiptLotInfo.LotAttr06,
                                            LotAttr07 = receiptLotInfo.LotAttr07,
                                            LotAttr08 = receiptLotInfo.LotAttr08,
                                            LotAttr09 = receiptLotInfo.LotAttr09,
                                            LotAttr10 = receiptLotInfo.LotAttr10,
                                            OwnerID = fromOwnerID,
                                            SkuID = fromSkuID,
                                            ProduceDate = receiptLotInfo.ProduceDate,
                                            ReceiptDate = receiptLotInfo.ReceiptDate,
                                            ExpiryDate = receiptLotInfo.ExpiryDate,
                                            ExternalLot = receiptLotInfo.ExternalLot,
                                            VendorID = receiptLotInfo.VendorID,
                                            CreatedBy = this.pubParasInfo.UserID,
                                            CreatedDate = DateTime.Now,
                                            UpdatedBy = this.pubParasInfo.UserID,
                                            UpdatedDate = DateTime.Now
                                        };
                                        lotAttributeDA.InsertLotAttribute(dataBase, tran, lotInfo, this.dataBaseID[0]);
                                        transferDetailInfo.ToLot = lotInfo.Lot;
                                    }
                                    else
                                    {
                                        transferDetailInfo.ToLot = lotID;
                                    }
                                    transferDetailInfo.TransferDate = DateTime.Now;
                                    transferDetailInfo.Status = "New";
                                    transferDetailInfo.Udf1 = (inventoryInfoList[j].AvailableQty - diffQty).ToString();
                                    transferDetailInfo.TransferLotInfo = receiptLotInfo;
                                    transferDetailInfoList.Add(transferDetailInfo);
                                }
                                break;
                            }
                        }
                    }
                    int lineID = 10;
                    foreach (TransferDetailInfo transferDetailInfo in transferDetailInfoList)
                    {
                        transferDetailInfo.LineID = lineID;
                        transferDetailInfo.TransferID = transferID;
                        transferDetailInfo.CreatedBy = this.pubParasInfo.UserID;
                        transferDetailInfo.CreatedDate = DateTime.Now;
                        transferDetailInfo.UpdatedBy = this.pubParasInfo.UserID;
                        transferDetailInfo.UpdatedDate = DateTime.Now;
                        transferDetailDA.InsertTransferDetail(dataBase, tran, transferDetailInfo, this.dataBaseID[0]);
                        lineID += 10;
                    }
                    tran.Commit();
                }
                catch (Exception ex)
                {
                    tran.Rollback();
                    CommonErrorHandler.ErrorHandler(ex, LogType.Error);
                }
                finally
                {
                    conn.Close();
                }
            }
            return result;
        }

        public string InsertInvBackup(string sInvDate)
        {
            string temp = string.Empty;
            string whLoginID = this.dataBaseID[0];
            HistoryStockRptQueryEntity historyStockRptQueryEntity = new HistoryStockRptQueryEntity {
                INV_DATE = sInvDate
            };
            List<string> sqlWhere = new List<string>();
            DataBase dataBase = new DataBase();
            DbConnection conn = dataBase.connection;
            conn.Open();
            DbTransaction tran = conn.BeginTransaction();
            try
            {
                if (invBackUpDA.GetInvBackUpByID(dataBase, tran, sInvDate, whLoginID) != null)
                {
                    invBackUpDA.DeleteInvBackUp(dataBase, tran, sInvDate, whLoginID);
                }
                temp = analyticsReportDA.InsertBackupHistoryStock(dataBase, tran, sqlWhere, historyStockRptQueryEntity, whLoginID, this.pubParasInfo).ToString();
                tran.Commit();
            }
            catch (Exception ex)
            {
                tran.Rollback();
                CommonErrorHandler.ErrorHandler(ex, LogType.Error);
            }
            finally
            {
                conn.Close();
            }
            return temp;
        }

        public string InsertInvMovesTrans(DataBase database, DbTransaction tran, InvMovesInfo invMovesInfo, string sourceTransType, string whLoginID)
        {
            InvTransInfo invTransInfo = new InvTransInfo {
                TransID = commonMethod.GenNextNumStr(database, tran, "INV_TRANS", whLoginID),
                TransType = TransType.Movement,
                OwnerID = invMovesInfo.ToOwnerID,
                SkuID = invMovesInfo.ToSkuID,
                Lot = invMovesInfo.ToLot,
                FromLoc = invMovesInfo.FromLoc,
                FromLpnID = invMovesInfo.FromLpn,
                ToLoc = invMovesInfo.ToLoc,
                ToLpnID = invMovesInfo.ToLpn,
                DocID = invMovesInfo.DocID,
                DocLineID = invMovesInfo.DocLineID,
                SourceTransType = sourceTransType,
                Status = TransStatus.OK
            };
            LotAttributeInfo lotInfo = lotAttributeDA.GetLotAttributeByID(database, tran, invMovesInfo.ToLot, whLoginID);
            if (lotInfo != null)
            {
                invTransInfo.LotAttr01 = lotInfo.LotAttr01;
                invTransInfo.LotAttr02 = lotInfo.LotAttr02;
                invTransInfo.LotAttr03 = lotInfo.LotAttr03;
                invTransInfo.LotAttr04 = lotInfo.LotAttr04;
                invTransInfo.LotAttr05 = lotInfo.LotAttr05;
                invTransInfo.LotAttr06 = lotInfo.LotAttr06;
                invTransInfo.LotAttr07 = lotInfo.LotAttr07;
                invTransInfo.LotAttr08 = lotInfo.LotAttr08;
                invTransInfo.LotAttr09 = lotInfo.LotAttr09;
                invTransInfo.LotAttr10 = lotInfo.LotAttr10;
                invTransInfo.ProduceDate = lotInfo.ProduceDate;
                invTransInfo.ExpiryDate = lotInfo.ExpiryDate;
                invTransInfo.ReceiptDate = lotInfo.ReceiptDate;
                invTransInfo.ExternalLot = lotInfo.ExternalLot;
                invTransInfo.VendorID = lotInfo.VendorID;
            }
            InvLotInfo invLotInfo = invLotDA.GetInvLotByID(database, tran, invMovesInfo.ToLot, whLoginID);
            if (invLotInfo != null)
            {
                invTransInfo.UnitPrice = invLotInfo.UnitPrice;
            }
            invTransInfo.Qty = invMovesInfo.MoveQty;
            invTransInfo.CaseCnt = 0M;
            invTransInfo.InnerPack = 0M;
            invTransInfo.Pallet = 0M;
            invTransInfo.Cube = 0.0;
            invTransInfo.GrossWgt = 0.0;
            invTransInfo.NetWgt = 0.0;
            invTransInfo.OtherUnit1 = 0.0;
            invTransInfo.OtherUnit2 = 0.0;
            invTransInfo.PackID = invMovesInfo.PackID;
            invTransInfo.UomID = invMovesInfo.UomID;
            invTransInfo.UomCalc = Convert.ToInt32(invMovesInfo.MoveQty);
            invTransInfo.UomQty = invMovesInfo.MoveQty;
            if (invMovesInfo.MoveDate != new DateTime())
            {
                invTransInfo.TransDate = invMovesInfo.MoveDate;
            }
            else
            {
                invTransInfo.TransDate = DateTime.Now;
            }
            invTransInfo.CreatedBy = invMovesInfo.UpdatedBy;
            invTransInfo.UpdatedBy = invMovesInfo.UpdatedBy;
            invTransDA.InsertInvTrans(database, tran, invTransInfo, whLoginID);
            return invTransInfo.TransID;
        }

        public string LpnSplit(List<LpnInfo> NewLpnInfo, InventoryInfo inventoryInfo, string strLpnID, string SplitType)
        {
            LPNGenerate lpnGenerate = new LPNGenerate();
            string CS40001 = SplitType.ToUpper();
            if ((CS40001 != null) && (CS40001 == "SKYTRANS"))
            {
                return lpnGenerate.SkyTransLpnSplit(NewLpnInfo, inventoryInfo, strLpnID, this.pubParasInfo, this.dataBaseID[0]);
            }
            return "未找到与拆分类型匹配的lpn方法,请核对！";
        }

        public void UpdateInvLot4Moves(DataBase database, DbTransaction tran, InvMovesInfo invMovesInfo, string invMoveType, string whLoginID)
        {
            InvLotInfo fromInvLotInfo = new InvLotInfo();
            fromInvLotInfo = invLotDA.GetInvLotByID(database, tran, invMovesInfo.FromLot, whLoginID);
            if ((fromInvLotInfo != null) && !string.IsNullOrEmpty(fromInvLotInfo.Lot))
            {
                if ((invMoveType == InvMoveType.Transfer) && (((((fromInvLotInfo.Qty - fromInvLotInfo.PreallocatedQty) - fromInvLotInfo.AllocatedQty) - fromInvLotInfo.PickedQty) - fromInvLotInfo.OnholdQty) < invMovesInfo.FromMoveQty))
                {
                    if (fromInvLotInfo.PreallocatedQty > 0M)
                    {
                        PublicMethod.GetInstance().ShowAlertMessage("F5050_011", this.pubParasInfo.UserLanguage, new List<string> { fromInvLotInfo.Lot });
                    }
                    if (fromInvLotInfo.AllocatedQty > 0M)
                    {
                        PublicMethod.GetInstance().ShowAlertMessage("F5050_012", this.pubParasInfo.UserLanguage, new List<string> { fromInvLotInfo.Lot });
                    }
                    else if (fromInvLotInfo.PickedQty > 0M)
                    {
                        PublicMethod.GetInstance().ShowAlertMessage("F5050_013", this.pubParasInfo.UserLanguage, new List<string> { fromInvLotInfo.Lot });
                    }
                    else if (fromInvLotInfo.OnholdQty > 0M)
                    {
                        PublicMethod.GetInstance().ShowAlertMessage("F5050_014", this.pubParasInfo.UserLanguage, new List<string> { fromInvLotInfo.Lot });
                    }
                }
                if (((((fromInvLotInfo.Qty - fromInvLotInfo.PreallocatedQty) - fromInvLotInfo.AllocatedQty) - fromInvLotInfo.PickedQty) - fromInvLotInfo.OnholdQty) >= 0M)
                {
                    if (invMoveType == InvMoveType.OwnerTransfer)
                    {
                        fromInvLotInfo.PickedQty -= invMovesInfo.FromMoveQty;
                    }
                    if (invMoveType == InvMoveType.Replenishment)
                    {
                        fromInvLotInfo.AllocatedQty -= invMovesInfo.FromMoveQty;
                    }
                    fromInvLotInfo.Qty -= invMovesInfo.FromMoveQty;
                    fromInvLotInfo.UpdatedBy = invMovesInfo.UpdatedBy;
                    invLotDA.UpdateInvLot(database, tran, fromInvLotInfo, whLoginID);
                    InvLotInfo invLotInfo = new InvLotInfo();
                    invLotInfo = invLotDA.GetInvLotByID(database, tran, invMovesInfo.ToLot, whLoginID);
                    if (!((invLotInfo == null) || string.IsNullOrEmpty(invLotInfo.Lot)))
                    {
                        invLotInfo.Qty += invMovesInfo.MoveQty;
                        invLotInfo.UpdatedBy = invMovesInfo.UpdatedBy;
                        invLotDA.UpdateInvLot(database, tran, invLotInfo, InvLotUpdateType.Qty, whLoginID);
                    }
                    else
                    {
                        InvLotInfo invFromLot = invLotDA.GetInvLotByID(database, tran, invMovesInfo.FromLot, whLoginID);
                        invLotInfo = new InvLotInfo {
                            Lot = invMovesInfo.ToLot,
                            OwnerID = invMovesInfo.ToOwnerID,
                            SkuID = invMovesInfo.ToSkuID,
                            Qty = invMovesInfo.MoveQty,
                            UnitPrice = invFromLot.UnitPrice,
                            CaseCnt = invFromLot.CaseCnt,
                            InnerPack = invFromLot.InnerPack,
                            Pallet = invFromLot.Pallet,
                            Cube = invFromLot.Cube,
                            GrossWgt = invFromLot.GrossWgt,
                            NetWgt = invFromLot.NetWgt,
                            OtherUnit1 = invFromLot.OtherUnit1,
                            OtherUnit2 = invFromLot.OtherUnit2,
                            Status = "OK",
                            CreatedBy = invMovesInfo.UpdatedBy,
                            UpdatedBy = invMovesInfo.UpdatedBy,
                            ArchiveDate = DateTime.Now
                        };
                        invLotDA.InsertInvLot(database, tran, invLotInfo, whLoginID);
                    }
                }
                else
                {
                    List<string> gInitLocale = new List<string> {
                        invMovesInfo.FromLoc,
                        invMovesInfo.FromLot,
                        invMovesInfo.FromLpn
                    };
                    PublicMethod.GetInstance().ShowAlertMessage("F5050_010", this.pubParasInfo.UserLanguage, gInitLocale);
                }
            }
        }

        public void UpdateInvLotLocLpn4Moves(DataBase database, DbTransaction tran, InvMovesInfo invMovesInfo, string invMoveType, string whLoginID)
        {
            InvLotLocLpnInfo fromInvLotLocLpnInfo = new InvLotLocLpnInfo();
            fromInvLotLocLpnInfo = invLotLocLpnDA.GetInvLotLocLpnByID(database, tran, invMovesInfo.FromLot, invMovesInfo.FromLoc, invMovesInfo.FromLpn, whLoginID);
            if (fromInvLotLocLpnInfo != null)
            {
                if (invMoveType == InvMoveType.Transfer)
                {
                    if (fromInvLotLocLpnInfo.AllocatedQty > 0M)
                    {
                        PublicMethod.GetInstance().ShowAlertMessage("F5050_002", this.pubParasInfo.UserLanguage, new List<string> { invMovesInfo.FromLoc, invMovesInfo.FromLot, invMovesInfo.FromLpn });
                    }
                    else if (fromInvLotLocLpnInfo.PickedQty > 0M)
                    {
                        PublicMethod.GetInstance().ShowAlertMessage("F5050_003", this.pubParasInfo.UserLanguage, new List<string> { invMovesInfo.FromLoc, invMovesInfo.FromLot, invMovesInfo.FromLpn });
                    }
                    else if (fromInvLotLocLpnInfo.ExpectedQty > 0M)
                    {
                        PublicMethod.GetInstance().ShowAlertMessage("F5050_004", this.pubParasInfo.UserLanguage, new List<string> { invMovesInfo.FromLoc, invMovesInfo.FromLot, invMovesInfo.FromLpn });
                    }
                    else if (fromInvLotLocLpnInfo.PickinprocessQty > 0M)
                    {
                        PublicMethod.GetInstance().ShowAlertMessage("F5050_005", this.pubParasInfo.UserLanguage, new List<string> { invMovesInfo.FromLoc, invMovesInfo.FromLot, invMovesInfo.FromLpn });
                    }
                    else if (fromInvLotLocLpnInfo.PendingMoveIn > 0M)
                    {
                        PublicMethod.GetInstance().ShowAlertMessage("F5050_017", this.pubParasInfo.UserLanguage, new List<string> { invMovesInfo.FromLoc, invMovesInfo.FromLot, invMovesInfo.FromLpn });
                    }
                }
                if ((((((fromInvLotLocLpnInfo.Qty - fromInvLotLocLpnInfo.AllocatedQty) - fromInvLotLocLpnInfo.PickedQty) - fromInvLotLocLpnInfo.ExpectedQty) - fromInvLotLocLpnInfo.PickinprocessQty) - fromInvLotLocLpnInfo.PendingMoveIn) >= 0M)
                {
                    if (invMoveType == InvMoveType.OwnerTransfer)
                    {
                        fromInvLotLocLpnInfo.PickedQty -= invMovesInfo.FromMoveQty;
                    }
                    if (invMoveType == InvMoveType.Replenishment)
                    {
                        fromInvLotLocLpnInfo.AllocatedQty -= invMovesInfo.FromMoveQty;
                    }
                    fromInvLotLocLpnInfo.Qty -= invMovesInfo.FromMoveQty;
                    fromInvLotLocLpnInfo.UpdatedBy = invMovesInfo.UpdatedBy;
                    invLotLocLpnDA.UpdateInvLotLocLpn(database, tran, fromInvLotLocLpnInfo, whLoginID);
                    InvLotLocLpnInfo invLotLocLpnInfo = null;
                    invLotLocLpnInfo = invLotLocLpnDA.GetInvLotLocLpnByID(database, tran, invMovesInfo.ToLot, invMovesInfo.ToLoc, invMovesInfo.ToLpn, whLoginID);
                    if (!((invLotLocLpnInfo == null) || string.IsNullOrEmpty(invLotLocLpnInfo.Loc)))
                    {
                        invLotLocLpnInfo.Qty += invMovesInfo.MoveQty;
                        invLotLocLpnInfo.UpdatedBy = invMovesInfo.UpdatedBy;
                        invLotLocLpnDA.UpdateInvLotLocLpn(database, tran, invLotLocLpnInfo, InvLotLocLpnUpdateType.Qty, whLoginID);
                    }
                    else
                    {
                        invLotLocLpnInfo = new InvLotLocLpnInfo {
                            Lot = invMovesInfo.ToLot,
                            Loc = invMovesInfo.ToLoc,
                            LpnID = invMovesInfo.ToLpn,
                            OwnerID = invMovesInfo.ToOwnerID,
                            SkuID = invMovesInfo.ToSkuID,
                            Qty = invMovesInfo.MoveQty,
                            Status = "OK",
                            ArchiveDate = DateTime.Now,
                            CreatedBy = invMovesInfo.UpdatedBy,
                            UpdatedBy = invMovesInfo.UpdatedBy
                        };
                        invLotLocLpnDA.InsertInvLotLocLpn(database, tran, invLotLocLpnInfo, whLoginID);
                    }
                }
                else
                {
                    List<string> gInitLocal5 = new List<string> {
                        invMovesInfo.FromLoc,
                        invMovesInfo.FromLot,
                        invMovesInfo.FromLpn
                    };
                    PublicMethod.GetInstance().ShowAlertMessage("F5050_006", this.pubParasInfo.UserLanguage, gInitLocal5);
                }
            }
        }

        public void UpdateInvLotLocLpnPendingQty(DataBase database, DbTransaction tran, string lotID, string locID, string lpnID, decimal pendingQty, string updatedBy, string whLoginID)
        {
            InvLotLocLpnInfo invLotLocLpnInfo = invLotLocLpnDA.GetInvLotLocLpnByID(database, tran, lotID, locID, lpnID, whLoginID);
            if (invLotLocLpnInfo != null)
            {
                invLotLocLpnInfo.PendingMoveIn += pendingQty;
                invLotLocLpnInfo.UpdatedBy = updatedBy;
                invLotLocLpnDA.UpdateInvLotLocLpn(database, tran, invLotLocLpnInfo, InvLotLocLpnUpdateType.PendingMoveIn, whLoginID);
            }
        }

        public void UpdateInvSkuLoc4Moves(DataBase database, DbTransaction tran, InvMovesInfo invMovesInfo, string invMoveType, string whLoginID)
        {
            InvSkuLocInfo fromInvSkuLocInfo = new InvSkuLocInfo();
            fromInvSkuLocInfo = invSkuLocDA.GetInvSkuLocByID(database, tran, invMovesInfo.FromOwnerID, invMovesInfo.FromSkuID, invMovesInfo.FromLoc, whLoginID);
            if (fromInvSkuLocInfo != null)
            {
                if (invMoveType == InvMoveType.Transfer)
                {
                    if (fromInvSkuLocInfo.AllocatedQty > 0M)
                    {
                        PublicMethod.GetInstance().ShowAlertMessage("F5050_007", this.pubParasInfo.UserLanguage, new List<string> { fromInvSkuLocInfo.Loc, fromInvSkuLocInfo.SkuID });
                    }
                    else if (fromInvSkuLocInfo.PickedQty > 0M)
                    {
                        PublicMethod.GetInstance().ShowAlertMessage("F5050_008", this.pubParasInfo.UserLanguage, new List<string> { fromInvSkuLocInfo.Loc, fromInvSkuLocInfo.SkuID });
                    }
                }
                if (((fromInvSkuLocInfo.Qty - fromInvSkuLocInfo.AllocatedQty) - fromInvSkuLocInfo.PickedQty) >= 0M)
                {
                    if (invMoveType == InvMoveType.OwnerTransfer)
                    {
                        fromInvSkuLocInfo.PickedQty -= invMovesInfo.FromMoveQty;
                    }
                    if (invMoveType == InvMoveType.Replenishment)
                    {
                        fromInvSkuLocInfo.AllocatedQty -= invMovesInfo.FromMoveQty;
                    }
                    fromInvSkuLocInfo.Qty -= invMovesInfo.FromMoveQty;
                    fromInvSkuLocInfo.UpdatedBy = invMovesInfo.UpdatedBy;
                    invSkuLocDA.UpdateInvSkuLoc(database, tran, fromInvSkuLocInfo, whLoginID);
                    InvSkuLocInfo invSkuLocInfo = null;
                    invSkuLocInfo = invSkuLocDA.GetInvSkuLocByID(database, tran, invMovesInfo.ToOwnerID, invMovesInfo.ToSkuID, invMovesInfo.ToLoc, whLoginID);
                    if (!((invSkuLocInfo == null) || string.IsNullOrEmpty(invSkuLocInfo.Loc)))
                    {
                        invSkuLocInfo.Qty += invMovesInfo.MoveQty;
                        invSkuLocInfo.UpdatedBy = invMovesInfo.UpdatedBy;
                        invSkuLocDA.UpdateInvSkuLoc(database, tran, invSkuLocInfo, InvSkuLocUpdateType.Qty, whLoginID);
                    }
                    else
                    {
                        invSkuLocInfo = new InvSkuLocInfo {
                            OwnerID = invMovesInfo.ToOwnerID,
                            SkuID = invMovesInfo.ToSkuID,
                            Loc = invMovesInfo.ToLoc,
                            Qty = invMovesInfo.MoveQty,
                            ReplenishmentPriority = "",
                            LocationType = "",
                            CreatedBy = invMovesInfo.UpdatedBy,
                            UpdatedBy = invMovesInfo.UpdatedBy
                        };
                        invSkuLocDA.InsertInvSkuLoc(database, tran, invSkuLocInfo, whLoginID);
                    }
                }
                else
                {
                    List<string> gInitLocal8 = new List<string> {
                        invMovesInfo.FromLoc,
                        invMovesInfo.FromLot,
                        invMovesInfo.FromLpn
                    };
                    PublicMethod.GetInstance().ShowAlertMessage("F5050_009", this.pubParasInfo.UserLanguage, gInitLocal8);
                }
            }
        }

        public void UpdateInvSkuLocExceptedQty(DataBase database, DbTransaction tran, string ownerID, string skuID, string locID, decimal exceptQty, string updatedBy, string whLoginID)
        {
            InvSkuLocInfo invSkuLocInfo = invSkuLocDA.GetInvSkuLocByID(database, tran, ownerID, skuID, locID, whLoginID);
            if (invSkuLocInfo != null)
            {
                invSkuLocInfo.ExpectedQty += exceptQty;
                invSkuLocInfo.UpdatedBy = updatedBy;
                invSkuLocDA.UpdateInvSkuLoc(database, tran, invSkuLocInfo, InvSkuLocUpdateType.ExpectedQty, whLoginID);
            }
            else
            {
                if (invSkuLocInfo == null)
                {
                    invSkuLocInfo = new InvSkuLocInfo();
                }
                invSkuLocInfo.OwnerID = ownerID;
                invSkuLocInfo.SkuID = skuID;
                invSkuLocInfo.Loc = locID;
                invSkuLocInfo.Qty = 0M;
                invSkuLocInfo.ExpectedQty = exceptQty;
                invSkuLocInfo.ReplenishmentPriority = "";
                invSkuLocInfo.LocationType = "";
                invSkuLocInfo.CreatedBy = updatedBy;
                invSkuLocInfo.UpdatedBy = updatedBy;
                invSkuLocDA.InsertInvSkuLoc(database, tran, invSkuLocInfo, whLoginID);
            }
        }

        public void UpdateLpn4Moves(DataBase database, DbTransaction tran, InvMovesInfo invMovesInfo, string whLoginID)
        {
            LpnInfo fromLpnInfo = new LpnInfo();
            fromLpnInfo = lpnDA.GetLpnByID(database, tran, invMovesInfo.FromLpn, whLoginID);
            if (fromLpnInfo != null)
            {
                if (fromLpnInfo.Qty >= 0M)
                {
                    fromLpnInfo.Qty -= invMovesInfo.FromMoveQty;
                    fromLpnInfo.UpdatedBy = invMovesInfo.UpdatedBy;
                    lpnDA.UpdateLpn(database, tran, fromLpnInfo, whLoginID);
                    LpnInfo lpnInfo = new LpnInfo();
                    lpnInfo = lpnDA.GetLpnByID(database, tran, invMovesInfo.ToLpn, whLoginID);
                    if (!((lpnInfo == null) || string.IsNullOrEmpty(lpnInfo.LpnID)))
                    {
                        lpnInfo.Qty += invMovesInfo.MoveQty;
                        lpnInfo.UpdatedBy = invMovesInfo.UpdatedBy;
                        lpnDA.UpdateLpn(database, tran, lpnInfo, LpnUpdateType.Qty, whLoginID);
                    }
                    else
                    {
                        if (lpnInfo == null)
                        {
                            lpnInfo = new LpnInfo();
                        }
                        if (!string.IsNullOrEmpty(invMovesInfo.ToLpn))
                        {
                            lpnInfo.LpnID = invMovesInfo.ToLpn;
                        }
                        else
                        {
                            lpnInfo.LpnID = commonMethod.GenNextNumStr(database, tran, "LPN", whLoginID);
                        }
                        lpnInfo.Qty = invMovesInfo.MoveQty;
                        lpnInfo.Status = "OK";
                        lpnInfo.PackID = invMovesInfo.PackID;
                        lpnInfo.Ipskey = "";
                        lpnInfo.CreatedBy = invMovesInfo.UpdatedBy;
                        lpnInfo.UpdatedBy = invMovesInfo.UpdatedBy;
                        lpnInfo.IsActive = fromLpnInfo.IsActive;
                        lpnInfo.DocID = fromLpnInfo.DocID;
                        lpnInfo.DocType = fromLpnInfo.DocType;
                        lpnDA.InsertLpn(database, tran, lpnInfo, whLoginID);
                    }
                }
                else
                {
                    List<string> gInitLocal9 = new List<string> {
                        invMovesInfo.FromLoc,
                        invMovesInfo.FromLot,
                        invMovesInfo.FromLpn
                    };
                    PublicMethod.GetInstance().ShowAlertMessage("F5050_010", this.pubParasInfo.UserLanguage, gInitLocal9);
                }
            }
        }
    }
}

